package com.inhim.pjhim.dowloadfile.adapter;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chaychan.adapter.MultipleItemRvAdapter;
import com.inhim.pjhim.dowloadfile.adapter.provider.DownloadingProvider;
import com.inhim.pjhim.dowloadfile.adapter.provider.HaveDownloadProvider;
import com.inhim.pjhim.dowloadfile.download.DownloadInfo;
import com.inhim.pjhim.entity.DownloadListLable;

import org.litepal.LitePal;

import java.util.List;
import java.util.Map;

/**
 * Created by jianghejie on 15/11/26.
 */
public class DownloadListAdapter<T> extends MultipleItemRvAdapter<T, BaseViewHolder> {
    public static final int DOWNLOADING = 100;
    public static final int HAVE_DOWNLOAD = 200;
    private Context context;
    private String TAG;
    private List<DownloadInfo> mdata;
    private DownloadingProvider mDownloadingProvider;
    public DownloadListAdapter(@Nullable List<T> data, Context context) {
        super(data);
        this.context = context;
        mDownloadingProvider=new DownloadingProvider(context);
        finishInitialize();//调用该方法告知MultipleItemRvAdapter1已初始化完构造函数参数的传递
    }

    @Override
    protected int getViewType(T news) {
        //纪录隐藏最后一个课程数据item的横线
        if (news instanceof DownloadInfo) {
            return DOWNLOADING;
        }else if (news instanceof DownloadListLable) {
            return HAVE_DOWNLOAD;
        }else {
            return 0;
        }
    }

    public void setCheck(boolean isCheck, Map<Integer, Boolean> mDeviceHeaderMap){
        if(mDownloadingProvider!=null){
            mDownloadingProvider.setCheck(isCheck,mDeviceHeaderMap);
        }
    }

    public DownloadingProvider getDownloadingProvider(){
        return mDownloadingProvider;
    }

    @Override
    public void registerItemProvider() {
        //注册itemProvider
        mProviderDelegate.registerProvider(mDownloadingProvider);
        mProviderDelegate.registerProvider(new HaveDownloadProvider(context));
    }

    private List<DownloadInfo> getDownloadListData() {
        List<DownloadInfo> myBusinessInfos = LitePal.findAll(DownloadInfo.class);
        if (myBusinessInfos.size() > 0) {
        }
        return myBusinessInfos;
    }
}





















